program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  fin: textfile;
  n, i, j, k: integer;
  mass: array of integer;
begin
  assignfile(fin, 'run.txt');
  reset(fin);
  readln(fin, n);
  setlength (mass, n);
  for I := 0 to n - 1 do
  begin
    read (fin, k);
    mass[i]:=k;
  end;
  for J := n-2 downto 0 do
  begin
    for I := 1 to j + 1 do
    begin
      if mass[i-1]<mass[i] then
      begin
        k:=mass[i];
        mass[i]:=mass[i-1];
        mass[i-1]:=k;
      end;
    end;
  end;
  k:= mass[0]+mass[n-1];
  writeln(k);
  readln;
end.
